package org.jsola.hr.web;

import lombok.extern.slf4j.Slf4j;
import org.jsola.core.Result;
import org.jsola.hr.constant.HrConstants;
import org.jsola.hr.provider.IContractProviderService;
import org.jsola.hr.provider.IMessageProviderService;
import org.jsola.hr.vo.ThirdConfigEnableVO;
import org.jsola.user.core.TokenUser;
import org.jsola.user.core.UserContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author JanusMix
 */
@Slf4j
@RestController("hrConfigController")
@RequestMapping(HrConstants.API_PATH + "/v1/hrConfigs")
public class HrConfigController implements IHrConfigControllerAPI {

    @Autowired
    private IContractProviderService contractProviderService;
    @Autowired
    private IMessageProviderService messageProviderService;

    @Override
    @GetMapping("/getEnabledConfig")
    public Result<ThirdConfigEnableVO> getEnabledConfig() {
        TokenUser tokenUser = UserContext.getUser();
        ThirdConfigEnableVO thirdConfigEnableVO = new ThirdConfigEnableVO();
        thirdConfigEnableVO.setContractEnable(contractProviderService.isSiteContractEnable(tokenUser));
        thirdConfigEnableVO.setMessageEnable(messageProviderService.isSiteMessageEnable(tokenUser));
        return Result.success(thirdConfigEnableVO);
    }
}
